package org.ysu.vo;

import lombok.Getter;
import org.ysu.core.RedisConfig;
import org.ysu.core.ResultCode;

@Getter
public class ResultVO<T> {
    private final Integer code;
    private final String message;
    private final T content;

    private ResultVO(Integer code, T content, String message) {
        this.code = code;
        this.message = message;
        this.content = content;
    }

    public static <T> ResultVO<T> getInstance(ResultCode resultCode, T content, String message) {
        return new ResultVO<T>(resultCode.getCode(),content,message);
    }

    public static <T> ResultVO<T> success( T content, String message ) {
        return getInstance(ResultCode.SUCCESS,content,message);
    }

    public static <T> ResultVO<T> success( T content ) {
        return getInstance(ResultCode.SUCCESS,content,null);
    }

    public static <T> ResultVO<T> failed( T content, String message ) {
        return getInstance(ResultCode.FAILED,content,message);
    }

    public static <T> ResultVO<T> failed( String message ) {
        return failed(null,message);
    }
    public static ResultVO unlogin(String message){
        return ResultVO.getInstance(ResultCode.UNLOGIN,null,message);
    }
    public static ResultVO forbid(){
        return ResultVO.getInstance(ResultCode.FORBID,null,"该用户无此操作权限");
    }
}
